<?php
/**
 * @author jy625
 */
namespace Weixinpay;
class MD5SignUtil {
	function sign($content, $key) {
		try {
			if (null == $key) {
				throw new \Think\Exception( "签名key不能为空！" . "<br>" );
			}
			if (null == $content) {
				throw new \Think\Exception( "签名内容不能为空" . "<br>" );
			}
			$signStr = $content . "&key=" . $key;

			return strtoupper ( md5 ( $signStr ) );
		} catch ( SDKRuntimeException $e ) {
			die ( $e->errorMessage () );
		}
	}
    function sign_hash($content, $key) {
        try {
            if (null == $key) {
                throw new \Think\Exception( "签名key不能为空！" . "<br>" );
            }
            if (null == $content) {
                throw new \Think\Exception( "签名内容不能为空" . "<br>" );
            }
//            $signStr = $content;
            $signStr = $content . "&key=" . $key;

            return strtoupper (hash_hmac("sha256",$signStr,$key));
        } catch ( SDKRuntimeException $e ) {
            die ( $e->errorMessage () );
        }
    }
	function verifySignature($content, $sign, $md5Key) {
		$signStr = $content . "&key=" . $md5Key;
		$calculateSign = strtolower ( md5 ( $signStr ) );
		$tenpaySign = strtolower ( $sign );
		return $calculateSign == $tenpaySign;
	}
}
?>